﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace COFE.Core.Actions
{
  

    public class WorkFinishedEventArgs : WorkEventArgs
    {
        public bool Success { get; private set; }        
        public Exception Error { get; private set; }

        public WorkFinishedEventArgs(IWork work, bool success, string message = null)
            : base(work, EventType.Finished, message)
        {
            Success = success;            
        }

        public WorkFinishedEventArgs(IWork work, Exception ex)
            : base(work, EventType.Failed, ex.Message)
        {
            Success = false;            
            Error = ex;
        }

        public static WorkFinishedEventArgs SuccessArgs(IWork work) { return new WorkFinishedEventArgs(work, true); }
        public static WorkFinishedEventArgs FailedArgs(IWork work, Exception ex) { return new WorkFinishedEventArgs(work, ex); }        
        public static WorkFinishedEventArgs AbortArgs(IWork work) { return new WorkFinishedEventArgs(work, new WorkAbortedException()); }

        //public override string ToString()
        //{
        //    if (Success)
        //        return String.Format("{0} - Success", ID);
        //    else                                
        //        return String.Format("{0} - {1}", ID, Message);
        //}

    }
}
